package com.swak.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;
import org.springframework.test.context.transaction.AfterTransaction;

@Aspect
@Service
@Order(value = 1)
public class LogAspect {

	@Pointcut("@annotation(com.swak.aop.TestLog)")
	public void cut() {
	}

	@Before("cut()")
	public void logstart() {
		System.out.println("log start");
	}

	@After("cut()")
	public void logend() {
		System.out.println("log end");
	}

	@AfterReturning("cut()")
	public void logreturn() {
		System.out.println("log return");
	}

	@AfterTransaction
	public void logexception() {
		System.out.println("log exception");
	}

	/**
	 * 需要手动推进
	 * 
	 * @param point
	 * @throws Throwable
	 */
	@Around("cut()")
	public Object logaround(ProceedingJoinPoint point) throws Throwable {
		System.out.println("log around -- start");
		Object object = point.proceed();
		System.out.println("log around -- end");
		return object;
	}
}
